﻿using System;
using System.ComponentModel;
using System.Linq.Expressions;

namespace Babylon.Toolbox
{
    public class SceneReference : INotifyPropertyChanged
    {
        string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name == value)
                    return;

                _name = value;

                RaisePropertyChanged(()=>Name);
            }
        }

        Guid _id;
        public Guid ID
        {
            get { return _id; }
            set
            {
                if (_id == value)
                    return;

                _id = value;

                RaisePropertyChanged(()=>ID);
            }
        }

        public SceneReference(string name, Guid id)
        {
            Name = name;
            ID = id;
        }

        public SceneReference(string name) : this(name, Guid.NewGuid())
        {            
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
        {
            var memberExpression = propertyExpression.Body as MemberExpression;
            if (memberExpression == null)
                return;

            string propertyName = memberExpression.Member.Name;
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
